package net.eyra.utiles;

import java.text.NumberFormat;
import java.util.Locale;

/**
 * @author Jorge Mejuto Created on 01-dic-2004
 */
public class Numeros {

    public static String Formateo(double numero) {
        NumberFormat nf = NumberFormat.getInstance();
        nf.setGroupingUsed(true);
        return nf.format(numero);
    }

    public static double Redondeo(double numero, int num_decimales) {
        NumberFormat n = NumberFormat.getInstance(Locale.US);
        n.setMaximumFractionDigits(num_decimales);
        n.setGroupingUsed(false);
        return new Double(n.format(numero)).doubleValue();
    }

    public static double RedondeoFP(double fp) {
        boolean negativo = false;
        if (fp < 0)
            negativo = true;

        if (Double.toString(fp).length() > 3) {
            if (new Integer(Double.toString(fp).substring(4, 5)).intValue() > 4)
                fp = fp + 0.01;
            // fp = new Double(Double.toString(fp).substring(1, 4)).doubleValue();
            if (fp < 1 && Double.toString(fp).length() > 3)
                fp = new Double(Double.toString(fp).substring(1, 4)).doubleValue();
            else
                fp = 1;
        }
        return negativo ? -fp : fp;
    }
}